/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 版本: 苏州公安统一用户管理平台1.0
 * <p>
 * 作者: 孙炯
 * <p>
 * 文件名:SysSsoLogController.java
 * <p>
 * 类产生时间: 2012-6-15 上午9:34:09
 * <p>
 * 负责人: 孙炯
 * 所在组 : 苏州公安统一用户管理平台
 * <p>
 * 所在部门: 电信/国土——技术二部
 * <p>
 * <p>
 */
package com.oceansoft.core.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hui.platform.system.Constants;
import com.hui.platform.system.utility.DatetimeUtil;
import com.hui.platform.system.utility.StringUtil;
import com.oceansoft.core.common.constant.Constant;
import com.oceansoft.core.common.util.Pagination;
import com.oceansoft.core.domain.Message;
import com.oceansoft.core.domain.SysSsoLog;
import com.oceansoft.core.domain.SysUser;
import com.oceansoft.core.service.ISysSsoLogService;

@Controller
@RequestMapping("/sso")
public class SysSsoLogController {
	@Resource
	private ISysSsoLogService sysSsoLogService;

	@RequestMapping("/log/{appId}")
	public void recordSsoLog(@PathVariable("appId") String appId, HttpServletRequest req, HttpServletResponse resp,
			ModelMap model) {
		String appName = req.getParameter("appName");
		SysUser user = (SysUser) req.getSession().getAttribute(Constant.LOGIN_USER);
		Message msg = new Message("单点日志记录成功！");
		try {
			sysSsoLogService.saveLog(user);
		} catch (Exception e) {   
			msg.setStatus(Constant.RESULT_FAILD);
			msg.setBody("单点日志记录失败!");
		}
		model.addAttribute("msg", msg);
	}

	@RequestMapping(value = "/query/{pageIndex}")
	public String query(@PathVariable("pageIndex") int pageIndex, ModelMap model, HttpServletRequest request) {
//		String userid = request.getParameter("userid");
//		String uname = request.getParameter("uname");
//		String logintime1 = request.getParameter("logintime1");
//		String logintime2 = request.getParameter("logintime2");
//		String targetsys = request.getParameter("targetsys");
//		Pagination<SysSsoLog> page = sysSsoLogService.findSsoInfoByConditions(userid, uname, targetsys, logintime1,
//				logintime2, pageIndex);
//		model.addAttribute("page", page);
//		model.addAttribute("userid", userid);
//		model.addAttribute("uname", uname);
//		model.addAttribute("targetsys", targetsys);
//		model.addAttribute("logintime1", logintime1);
//		model.addAttribute("logintime2", logintime2);
		String nowDate=DatetimeUtil.getCurrentDateAsString("yyyy-MM-dd");
		model.addAttribute("nowDate",nowDate);
		return "syslog/sso_list";
	}
	
	@RequestMapping(value = "/query/list.json")
	public ModelAndView list(ModelMap model, HttpServletRequest request) {
		ModelAndView modelAndView = new ModelAndView(Constants.RESPONSE_VIEW);
		String pageIndex = request.getParameter("page");
		if(StringUtil.isNull(pageIndex))
		{
			pageIndex = "1";
		}
		String userid = request.getParameter("userid");
		String uname = request.getParameter("uname");
		String logintime1 = request.getParameter("logintime1");
		String logintime2 = request.getParameter("logintime2");
		String targetsys = request.getParameter("targetsys");
		Pagination<SysSsoLog> page = sysSsoLogService.findSsoInfoByConditions(userid, uname, targetsys, logintime1,
				logintime2, Integer.parseInt(pageIndex));
		modelAndView.addObject("rows",page.getList());
		modelAndView.addObject("total",page.getTotalRows());
		return modelAndView;
	}
}
